<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
include_once('../class/xmlparser.php');
$XMLFile = "../config/playlist{$Lang}.xml";	
$XML = new xmlparser();
$XML = $XML -> ReadDatabase($XMLFile,"track");
$xCount = is_numeric($_GET['nu']) ? $_GET['nu'] : count($XML);

if($_POST['Action'] == 'UpDate'){
	$ncz = true;
	$up = new upload();
	$up->save_dir = '../uploadfile/Media/';	
	$up->save_son_dir = false;	
	
	$vcl = "\r\n";
	$nXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>{$vcl}";
	$nXML .= "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">{$vcl}";
	$nXML .= "	<trackList>{$vcl}";

	for($i=0; $i<$xCount; $i++){
		if(!empty($_FILES["image{$i}"]['tmp_name'])){
			$up->ispics = true;
			$up->field_name = "image{$i}";
			$up->new_filename = "video_pics_{$Lang}_".($i+1);
			if($up->perform()){
				$images[$i] = str_replace('../','',$up->URL);	
			} else {
				$images[$i] = $XML[$i]['image'];
				$ncz = $up->info; //捕获失败的上传信息
			}			
		} else {
			$images[$i] = $XML[$i]['image'];
		}
		
		if(!empty($_FILES["video{$i}"]['tmp_name'])){
			$up->ispics = false;
			$up->field_name = "video{$i}";
			$up->new_filename = "video_file_{$Lang}_".($i+1);
			if($up->perform()){
				$video[$i] = $up->URL;	
			} else {
				$video[$i] = $_POST['location'][$i];
				$ncz = $up->info; //捕获失败的上传信息
			}			
		} else {
			$video[$i] = $_POST['location'][$i];
		}
		if(substr($video[$i],0,7)!='http://' && substr($video[$i],0,3)!='../'){$video[$i] = "../{$video[$i]}";}
		
		$nXML .= "		<track>{$vcl}";
		$nXML .= "			<image>{$images[$i]}</image>{$vcl}";
		$nXML .= "			<title>" . htmlspecialchars(stripcslashes($_POST['title'][$i]),ENT_QUOTES) . "</title>{$vcl}";
		$nXML .= "			<creator>" . htmlspecialchars(stripcslashes($_POST['creator'][$i]),ENT_QUOTES) . "</creator>{$vcl}";
		$nXML .= "			<location>" . htmlspecialchars(stripcslashes($video[$i]),ENT_QUOTES) . "</location>{$vcl}";
		$nXML .= "		</track>{$vcl}";
	}
	$nXML .= "	</trackList>{$vcl}";
	$nXML .= "</playlist>";
	
	if(!@$fp = fopen($XMLFile,'w')) MsgBox(1,"没有写入 $XMLFile 的权限！","1");
	$fw = fwrite($fp,$nXML);
	fclose($fp);	
	AdminLog(1,1,'修改视频播放管理，结果：操作成功！');
	if($ncz !== true) MsgBox (1,'数据修改成功，有部分文件未能上传，返回上传信息：'.$ncz,'1');
	MsgBox (1,'数据修改成功！','1');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link href="../tools/highslide/highslide.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../tools/highslide/highslide.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
hs.graphicsDir = '../tools/highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'rounded-white';
hs.restoreTitle = '关闭';
</script>
<style type="text/css">
.jq{border-bottom:1px #000 solid;}
.jqb{font-family:Verdana, Geneva, sans-serif; font-size:16px; font-weight:bold; border-bottom:1px #000 solid; font-style:italic; color:#066;}
</style>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td><?php TopLang();?></td><td align="right">
		设置视频数量：
		<select OnChange="window.open(this.options[this.selectedIndex].value,'_self')" size="1">
		<?php
		for ($i=1; $i<=20; $i++ ) {
			if($i != $xCount){
				echo '<option value="VideoManage.php?Lang=' . $Lang . '&nu=' . $i . '">' . $i . '</option>' . "\n";
			}else{
				echo '<option selected="selected" value="VideoManage.php?&Lang=' . $Lang . '&nu=' . $i . '">' . $i . '</option>' . "\n";
			}
		}
		?>  	
		</select>		
	</td></tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <tr>
    <td colspan="4" align="center" class="Main_Title">视频播放管理<?php echo $OnWebLangName?></td>
  </tr>
<?php
for($i=0; $i<$xCount; $i++){
?>  
  <tr class="odd">
  	<td rowspan="5" align="center" class="jqb"><?php echo ($i+1)?></td>
    <td height="20" align="right">主标题：</td>
    <td><input name="creator[]" type="text" value="<?php echo $XML[$i]['creator']?>" class="input2" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr class="odd">
  	<td height="20" align="right">副标题：</td>
  	<td><input name="title[]" type="text" value="<?php echo $XML[$i]['title']?>" class="input2" /></td>
  	<td>显示在主标题后面，可以填写日期、视频来源等信息</td>
  	</tr>
  <tr class="odd">
  	<td height="20" align="right">预览图片：</td>
  	<td><input name="image<?php echo $i?>" type="file" size="35" /></td>
  	<td><a href="<?php echo "../{$XML[$i]['image']}"?>" onclick="return hs.expand(this);">图片预览</a></td>
  	</tr>
  <tr class="odd">
  	<td height="20" align="right">上传视频：</td>
  	<td><input name="video<?php echo $i?>" type="file" size="35" /></td>
  	<td>&nbsp;</td>
  	</tr>
  <tr class="odd">
  	<td height="20" align="right" class="jq">视频路径：</td>
  	<td class="jq"><input name="location[<?php echo $i?>]" type="text" value="<?php echo $XML[$i]['location']?>" class="input2" /></td>
  	<td class="jq">建议使用外部视频文件</td>
  	</tr>
<?php }?>	
  <tr class="odd">
  	<td align="right" height="30">&nbsp;</td>
  	<td height="40" align="right">&nbsp;</td>
  	<td>
  		<input type="submit" name="button" id="button" value="修 改" class="submit" /><input name="Action" type="hidden" value="UpDate" />
  		</td>
  	<td>&nbsp;</td>
  	</tr>
	</form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
注：1、不更换图片时不用上传,上传将会替换当前图片；<br />
　　2、过大的视频文件请采用FTP上传至服务器，或采用外部视频文件，外部视频必须以 "http://" 开头。<br />
　　3、当前允许上传的文件类型有：<span class="Igreen"><?php echo $ps['upload']['annex_type'];?></span>，文件上传类型及上传大小在 图片处理设置(商业版) 或 config/pics.php(免费版)文件中修改。<br />
　　4、文件过大时请采用FTP软件上传至服务器后填写文件地址(内、外部均可)，本页适用于上传10M以下的文件(视服务器及网络状况而定)；<br />
　　5、当前服务器上传限制：upload_max_filesize(<?php echo get_cfg_var("upload_max_filesize");?>)；post_max_size(<?php echo get_cfg_var("post_max_size");?>)。
		</td>
	</tr>
</table>  
</body>
</html>